#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>
#include <QGridLayout>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

//    QPushButton* btn1 = new QPushButton();
//    QPushButton* btn2 = new QPushButton();
//    QPushButton* btn3 = new QPushButton();
//    QPushButton* btn4 = new QPushButton();
//    QPushButton* btn5 = new QPushButton();
//    QPushButton* btn6 = new QPushButton();

//    // 创建网格布局
//    QGridLayout* layout = new QGridLayout();
//    layout->addWidget(btn1, 0 ,0);
//    layout->addWidget(btn2, 0 ,1);
//    layout->addWidget(btn3, 0 ,2);
//    layout->addWidget(btn4, 1 ,0);
//    layout->addWidget(btn5, 1 ,1);
//    layout->addWidget(btn6, 1 ,2);

//    // 设置拉伸
//    layout->setColumnStretch(0, 1);
//    // 0固定大小，不拉伸
//    layout->setColumnStretch(1, 0);
//    layout->setColumnStretch(2, 3);

//    this->setLayout(layout);

    // 垂直拉伸
    QPushButton* btn1 = new QPushButton();
    QPushButton* btn2 = new QPushButton();
    QPushButton* btn3 = new QPushButton();
    QPushButton* btn4 = new QPushButton();
    QPushButton* btn5 = new QPushButton();
    QPushButton* btn6 = new QPushButton();
    // 设置尺寸策略
    btn1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn5->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn6->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    // 创建网格布局
    QGridLayout* layout = new QGridLayout();
    layout->addWidget(btn1, 0 ,0);
    layout->addWidget(btn2, 0 ,1);
    layout->addWidget(btn3, 0 ,2);
    layout->addWidget(btn4, 1 ,0);
    layout->addWidget(btn5, 1 ,1);
    layout->addWidget(btn6, 1 ,2);

    // 设置拉伸
    layout->setRowStretch(0, 1);
    // 0固定大小，不拉伸
    layout->setRowStretch(1, 0);
    layout->setRowStretch(2, 3);

    this->setLayout(layout);
}

Widget::~Widget()
{
    delete ui;
}

